/*
 * @lc app=leetcode.cn id=605 lang=swift
 *
 * [605] 种花问题
 */

// @lc code=start
class Solution {
    func canPlaceFlowers(_ flowerbed: [Int], _ n: Int) -> Bool {
        var zeroCount = 1
        var floor = 0
        for i in 0..<flowerbed.count {
            if flowerbed[i] == 0 {
                zeroCount += 1
            } else {
                floor += (zeroCount-1)/2
                zeroCount = 0
            }
        }
        zeroCount += 1
        floor += (zeroCount-1)/2
        return floor >= n
    }
}
// @lc code=end

